#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 10;

int n;
string s, t;
vector<string> a, b;
vector<string> change(string s, string a, string b) {
  vector<string> res;
  size_t pos = 0;
  while ((pos = s.find(a, pos)) != string::npos) {
    string t = s.substr(0, pos) + b + s.substr(pos + a.size());
    res.push_back(t);
    pos++;
  }
  return res;
}
int bfs() {
  map<string, int> dmn, dmx;
  queue<string> qmn, qmx;
  qmn.push(s), qmx.push(t);
  dmn[s] = 0, dmx[t] = 0;
  int step = 0;
  while (++step <= 10) {
    queue<string> tmp;
    while (qmn.size()) {
      string s = qmn.front();
      qmn.pop();
      rep(i, 0, n - 1) {
        for (string t : change(s, a[i], b[i])) {
          if (!dmn.count(t)) {
            dmn[t] = dmn[s] + 1;
            if (dmx.count(t)) return dmn[t] + dmx[t];
            tmp.push(t);
          }
        }
      }
    }
    swap(qmn, tmp);
    swap(qmn, qmx);
    swap(dmn, dmx);
    swap(a, b);
  }
  return -1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s >> t;
  string s1, s2;
  while (cin >> s1 >> s2) {
    ++n;
    a.push_back(s1), b.push_back(s2);
  }
  int ans = bfs();
  if (ans == -1)
    cout << "NO ANSWER!";
  else
    cout << ans;
  return 0;
}